#!/bin/sh

die () { echo "$@" ; exit 1; }

\. ../../../nvm.sh

yes_creds() {
  nvm_url_has_credentials "${1}" || die "nvm_url_has_credentials '${1}': expected success"
}

no_creds() {
  ! nvm_url_has_credentials "${1}" || die "nvm_url_has_credentials '${1}': expected failure"
}

yes_creds 'https://user:pw@mirror.example/dist'
yes_creds 'http://user:pw@127.0.0.1:8080/dist/index.tab'
yes_creds 'https://user@mirror.example'
yes_creds 'https://user:pw@[::1]:8080/dist'
yes_creds 'https://user:p@ss@mirror.example/dist'
yes_creds 'https://user:pw@mirror.example/a"b\c'

no_creds 'https://nodejs.org/dist/index.tab'
no_creds 'https://mirror.example/dist/@scope/index.tab'
no_creds 'https://mirror.example/user:pw@elsewhere.example/dist'
no_creds ''
no_creds '-o'
no_creds 'user:pw@mirror.example/dist'
no_creds 'ftp://user:pw@mirror.example/dist'
no_creds '/tmp/user:pw@mirror.example/node.tar.xz'
no_creds 'https://user:pw@mirror.example/a b'
no_creds "$(printf 'https://user:pw@mirror.example/a\nb')"
no_creds "$(printf 'https://user:pw@mirror.example/a\rb')"
no_creds "$(printf 'https://user:pw@mirror.example/a\033b')"
